package com.ruoyi.pingjiao.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pingjiao.domain.query.StatisticQueryParam;
import com.ruoyi.pingjiao.domain.vo.EvaluationReportVO;
import com.ruoyi.pingjiao.service.IEvaluationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("统计管理")
@RestController
@RequestMapping("/pingjiao/statistic")
public class StatisticController extends BaseController {
    @Autowired
    IEvaluationService evaluationService;

    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
    @GetMapping("/getAllEvaluationReport")
    public TableDataInfo getAllEvaluationReport(StatisticQueryParam queryParam)
    {
        startPage();
        List<EvaluationReportVO> list = evaluationService.getAllEvaluationReport(queryParam);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, StatisticQueryParam queryParam)
    {
        List<EvaluationReportVO> list = evaluationService.getAllEvaluationReport(queryParam);
        ExcelUtil<EvaluationReportVO> util = new ExcelUtil<EvaluationReportVO>(EvaluationReportVO.class);
        util.exportExcel(response, list, "统计分析");
    }

    /**
     * cjb,最终汇总，得分明细，查看某教师某个评教活动中试卷各分项得分
     *
     */
    @ApiOperation("获取问卷得分详情")
    @ApiImplicitParams({@ApiImplicitParam(name= "evaluationActivityId", value = "评价活动Id", required = true, dataType = "int"),
            @ApiImplicitParam(name= "teacherId", value = "教师Id", required = true, dataType = "int")
    })

    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
    @GetMapping("/getTeacherEvaluationPaperItemScoreReport/{evaluationActivityId}/{teacherId}")
    public AjaxResult getTeacherEvaluationPaperItemScoreReport(@PathVariable Long evaluationActivityId,
                                                               @PathVariable Long teacherId)
    {
        List<Map<String,Object>> list = evaluationService.getTeacherEvaluationPaperItemScoreReport(evaluationActivityId,teacherId);
        return AjaxResult.success(list);
    }

    /**
     * hpf
     * 某活动统计部门的排名
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
    @GetMapping("/getDeptRank/{evaluationActivityId}")
    public AjaxResult getDeptRank(@PathVariable Long evaluationActivityId)
    {
        List<Map<String,Object>> list = evaluationService.getDeptRank(evaluationActivityId);
        return AjaxResult.success(list);
    }

    /**
     * cjb 教师担任多门课程，可以参加分课程排序，在学院或二级学院排序中可以平均分计算。
     * @param evaluationActivityId
     * @param deptId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
    @GetMapping("/getDeptScopeTeacherEvaluationReport/{evaluationActivityId}/{deptId}")
    public TableDataInfo getDeptScopeTeacherEvaluationReport(@PathVariable Long evaluationActivityId,
                                                             @PathVariable Long deptId)
    {
        startPage();
        List<EvaluationReportVO> list = evaluationService.getDeptScopeTeacherEvaluationReport(evaluationActivityId,deptId);
        return getDataTable(list);
    }
//    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
//    @GetMapping("/departmentTeacherOrientedEvaluation/{evaluationActivityId}")
//    public TableDataInfo departmentTeacherOrientedEvaluation(@PathVariable Long evaluationActivityId)
//    {
//        startPage();
//        List<EvaluationReportVO> list = evaluationService.getAllEvaluationReport(evaluationActivityId);
//        return getDataTable(list);
//    }
//    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
//    @GetMapping("/courseOrientedEvaluation/{evaluationActivityId}")
//    public TableDataInfo courseOrientedEvaluation(@PathVariable Long evaluationActivityId)
//    {
//        startPage();
//        List<EvaluationReportVO> list = evaluationService.getAllEvaluationReport(evaluationActivityId);
//        return getDataTable(list);
//    }


    /**
     * cjb,最终汇总，得分明细，查看某教师某个评教活动中试卷各分项得分
     *
     */
    @ApiOperation("统计全校教师评教各分数段人数")
    @ApiImplicitParams({@ApiImplicitParam(name= "evaluationActivityId", value = "评价活动Id", required = true, dataType = "int")
    })

    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
    @GetMapping("/getGradeWithActivityId/{evaluationActivityId}")
    public AjaxResult getGradeWithActivityId(@PathVariable Long evaluationActivityId)
    {
        List<Map<String,Object>> list = evaluationService.getGradeWithActivityId(evaluationActivityId);
        return AjaxResult.success(list);
    }

    /**
     * cjb,最终汇总，得分明细，查看某教师某个评教活动中试卷各分项得分
     *
     */
    @ApiOperation("统计全校教师评教各分数段人数")
    @ApiImplicitParams({@ApiImplicitParam(name= "evaluationActivityId", value = "评价活动Id", required = true, dataType = "int"),
            @ApiImplicitParam(name= "dept_name", value = "院系名称", required = true, dataType = "String")
    })

    @PreAuthorize("@ss.hasPermi('pingjiao:statistic:list')")
    @GetMapping("/getGradeWithActivityIdAndDeptName/{evaluationActivityId}/{dept_name}")
    public AjaxResult getGradeWithActivityIdAndDeptName(@PathVariable Long evaluationActivityId,
                                                               @PathVariable String dept_name)
    {
        HashMap map=new HashMap();
        map.put("evaluation_activity_id",evaluationActivityId);
        map.put("dept_name",dept_name);
        List<Map<String,Object>> list = evaluationService.getGradeWithActivityIdAndDeptName(map);
        return AjaxResult.success(list);
    }


}
